{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import steward as st\n",
    "import matplotlib.pyplot as plt\n",
    "import pickle\n",
    "import xgboost\n",
    "from sklearn.metrics import roc_auc_score\n",
    "%matplotlib inline\n",
    "from src import build\n",
    "from src import test, config\n",
    "from src.feature_cols import to_drop\n",
    "from src.build import col_info"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "build.build_all()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# ma = st.get_default_manager()\n",
    "# train = ma['origin/train_all'].load()\n",
    "\n",
    "# train_mean = train[col_info.cont_columns].mean()\n",
    "\n",
    "# @st.as_op()\n",
    "# def gen_cont(origin):\n",
    "#     cont = origin[col_info.cont_columns]\n",
    "#     cont = cont.fillna(train_mean).fillna(0)\n",
    "#     return cont\n",
    "\n",
    "# test = ma['origin/test_all'].load()\n",
    "\n",
    "# cont_test_use_train_mean = gen_cont(test, name='cont_test_use_train_mean')\n",
    "\n",
    "# st.save_to_file(cont_test_use_train_mean)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<steward.instance.LoadInstance at 0x7f3926d17898>"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "st.LoadInstance('cont_test_use_train_mean')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "feature_list = [\n",
    "#     'cont_test_use_train_mean',\n",
    "    'basic_preprocess/cont_test_all',\n",
    "#     'basic_preprocess/conc_test_all'\n",
    "]\n",
    "info = 'basic_preprocess/info_test_all'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "__x = []\n",
    "for name in feature_list:\n",
    "    __x.append(st.get_instance(name).load())\n",
    "\n",
    "info_df = st.get_instance(info).load()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "for i in range(len(__x)):\n",
    "    __x[i] = __x[i].values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "X = np.concatenate(__x, axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false,
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "5.37%\n",
      "10.74%\n",
      "16.11%\n",
      "20.14%\n",
      "25.51%\n",
      "30.88%\n",
      "36.25%\n",
      "40.28%\n",
      "45.65%\n",
      "51.02%\n",
      "55.04%\n",
      "60.41%\n",
      "65.78%\n",
      "71.15%\n",
      "75.18%\n",
      "80.55%\n",
      "85.92%\n",
      "91.29%\n",
      "95.32%\n",
      "100.69%\n"
     ]
    }
   ],
   "source": [
    "test.test_iters(X, info_df, use_fold_model=None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "info_df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "__x[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python [conda root]",
   "language": "python",
   "name": "conda-root-py"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
